import React, { Component } from 'react';
import WrapFormItem from "components/wrap-form-item";
import CompactInput from "components/compact-input";
import { messages } from "share/common";
import Chooser from "components/chooser";
import { Select, Input } from 'antd';

const { Option } = Select;

class EditSuitStaff extends Component {

  state = {
    value: {}
  };

  componentDidMount() {
    this.setValues(this.props);
  }

  componentWillReceiveProps(nextProps) {
    this.setValues(nextProps);
  }

  setValues = props => {
    if('value' in props) {
      const value = props.value;
      this.setState({ value });
    }
  };

  handleOnChange = value => {
    const { onChange } = this.props;
    this.setState({ value });
    onChange(value);
  };

  render () {

    const { priority } = this.props;
    const { value } = this.state;
    const { levelOrgId } = priority || {};
    let listExtraParams = levelOrgId ? { levelOrgId } : {};

    return (
      <WrapFormItem
        value={value}
        onChange={value => this.handleOnChange(value)}
      >
        {(onChangeValue, val) => (
          <CompactInput>
            <Select
              onChange={key => onChangeValue({ staffType: key, reviewEditSuitStaff: [] })}
              value={val.staffType}
            >
              <Option key={'ALL'}>{messages('common.all')/*全部*/}</Option>
              <Option key={'PART'}>{messages('common-1.key426')/*部分*/}</Option>
            </Select>
            {val.staffType === 'ALL'
              ? <Input
                disabled
                value={messages('common-1.key421')/*通用*/}
              />
              : <Chooser
                type='user_group'
                labelKey='name'
                valueKey='id'
                listExtraParams={listExtraParams}
                onChange={reviewEditSuitStaff => onChangeValue({ reviewEditSuitStaff })}
                value={val.reviewEditSuitStaff}
              />
            }
          </CompactInput>
        )}
      </WrapFormItem>
    )
  }

}

export default EditSuitStaff
